unit uTextEditForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, dx_vgcore, Buttons;

type
  TTextEditForm = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    BitBtn1: TBitBtn;
    FontDialog1: TFontDialog;
    procedure FormActivate(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    vxText: TvxText;
  end;

var
  TextEditForm: TTextEditForm;

implementation

{$R *.dfm}

procedure TTextEditForm.FormActivate(Sender: TObject);
var
  fontStyle: TFontStyles;
begin
  Memo1.Lines.Text := vxText.Text;
  Memo1.Font.Name := vxText.Font.Family;
  Memo1.Font.Size := Round(vxText.Font.Size);
  fontStyle := [];
  case vxText.Font.Style of
  vgFontBold:
    begin
      Include(fontStyle, fsBold);
    end;
  vgFontItalic:
    begin
      Include(fontStyle, fsItalic);
    end;
  vgFontBoldItalic:
    begin
      Include(fontStyle, fsBold);
      Include(fontStyle, fsItalic);
    end;
  vgFontUnderline:
    begin
      Include(fontStyle, fsUnderline);
    end;
  vgFontStrikeout:
    begin
      Include(fontStyle, fsStrikeOut);
    end;
  vgFontRegular:
    begin
      fontStyle := [];
    end;
  end;
  Memo1.Font.Style := fontStyle;
  Memo1.Font.Color := vgStrToColor(vxText.Fill.Color);
end;

procedure TTextEditForm.BitBtn1Click(Sender: TObject);
begin
  FontDialog1.Font := Memo1.Font;
  if FontDialog1.Execute then
  begin
     Memo1.Font := FontDialog1.Font;
  end;
end;

procedure TTextEditForm.Button2Click(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

procedure TTextEditForm.Button1Click(Sender: TObject);
begin
  vxText.Text := Memo1.Lines.Text;
  vxText.Font.Family := Memo1.Font.Name;
  vxText.Font.Size := Memo1.Font.Size;
  if (fsBold in Memo1.Font.Style) and (fsItalic in Memo1.Font.Style) then
    vxText.Font.Style := vgFontBoldItalic
  else if (fsBold in Memo1.Font.Style) then
    vxText.Font.Style := vgFontBold
  else if (fsItalic in Memo1.Font.Style) then
    vxText.Font.Style := vgFontItalic
  else if (fsUnderline in Memo1.Font.Style) then
    vxText.Font.Style := vgFontUnderline
  else if (fsStrikeOut in Memo1.Font.Style) then
    vxText.Font.Style := vgFontStrikeout;
  vxText.Fill.Color := vgColorToStr(vgColorFromVCL(Memo1.Font.Color));
  ModalResult := mrOK;
end;

end.
